#include <stdio.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h>

void RunChild(){
    printf("i am a child, pid = %d, ppid = %d\n", getpid(), getppid());
    return;
}

int main(){
    pid_t id = fork();
    if(id < 0){
        printf("create child process failed!\n");
        return 0;
    }
    //父进程
    if(id > 0){
        pid_t ret = wait(NULL);
        if(ret != -1){
            printf("wait success, pid = %d\n", ret);
        }else{
            printf("filed success\n");
        }
        sleep(5);
    }else{//子进程
       RunChild();
       exit(0);//关闭子进程
    }

    return 0;
}
